package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.esm.model.User;
import com.esm.service.AddMsgService;
import com.esm.serviceimpl.AddMsgServiceImpl;

import net.sf.json.JSONObject;

public class ReturnMsgController extends HttpServlet{
	AddMsgService ad=new AddMsgServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
		
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		HttpSession session=req.getSession();
		User curUser=(User) session.getAttribute("currentUser");
		int uid=curUser.getUid();
		int oid=Integer.parseInt(req.getParameter("oid"));
		String lgroup=req.getParameter("lgroup");
		String lcontent=req.getParameter("lcontent");
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String pushTime=df.format(new Date());
		int isReturn=1;
		int state=1;
		boolean returnFlag=ad.addReturnMsg(uid, lcontent, oid, pushTime, isReturn, state, lgroup);
		JSONObject j=new JSONObject();
		j.put("flag", returnFlag);
		PrintWriter pw=resp.getWriter();
		pw.write(j.toString());
	}
}
